﻿using UnityEngine;
using System.Collections;


[RequireComponent(typeof(RunnerCharacter))]
[RequireComponent(typeof(Animator))]
public class RunnerAnimator : MonoBehaviour
{

    private Animator anim;
    private RunnerCharacter runner;

    void Awake()
    {
        anim = GetComponent<Animator>();
        runner = GetComponent<RunnerCharacter>();
    }

    // Update is called once per frame
    void Update()
    {
        switch (runner.Status)
        {
            case RunnerCharacter.RunnerStatus.Running:
                if (!anim.GetCurrentAnimatorStateInfo(0).IsName("Run"))
                    anim.SetTrigger("Run");
                break;
            case RunnerCharacter.RunnerStatus.Jumping:
                if (!anim.GetCurrentAnimatorStateInfo(0).IsName("JumpUp") && runner.Velocity.y > 0.05f)
                    anim.SetTrigger("JumpUp");
                if (!anim.GetCurrentAnimatorStateInfo(0).IsName("JumpDown") && runner.Velocity.y < -0.05f)
                    anim.SetTrigger("JumpDown");
                break;
            case RunnerCharacter.RunnerStatus.Sliding:
                if (!anim.GetCurrentAnimatorStateInfo(0).IsName("Slide"))
                    anim.SetTrigger("Slide");
                break;

        }
    }
}
